import { RootState } from '@/types/store'
import { useEffect } from 'react'
import { useDispatch, useSelector } from 'react-redux'
export default function useInitialState<StateName extends keyof RootState> (action:()=>void, stateName:StateName) {
  const dispatch = useDispatch()
  useEffect(() => {
    dispatch(action())
  }, [dispatch, action])

  const state = useSelector((state:RootState) => state[stateName])
  return state
}
